import { t } from '@/locales/i18n';
import { LLMModelTypeEnum } from '@/types/ai/constants';

import {
  FlowNodeInputTypeEnum,
  FlowNodeOutputTypeEnum,
  FlowNodeTemplateTypeEnum,
  FlowNodeTypeEnum,
  NodeInputKeyEnum,
  NodeOutputKeyEnum,
  WorkflowIOValueTypeEnum,
} from '../../constant';
import { FlowNodeTemplateType } from '../../node';
import {
  Input_Template_History,
  Input_Template_SettingAiModel,
  Input_Template_System_Prompt,
  Input_Template_UserChatInput,
  Input_Template_UserChatInput2,
} from '../input';
import { chatNodeSystemPromptTip, systemPromptTip } from '../tip';
import { getHandleConfig } from '../utils';

export const ToolModule: FlowNodeTemplateType = {
  id: FlowNodeTypeEnum.tools,
  flowNodeType: FlowNodeTypeEnum.tools,
  templateType: FlowNodeTemplateTypeEnum.ai,
  sourceHandle: getHandleConfig(true, true, false, true),
  targetHandle: getHandleConfig(true, true, false, true),
  avatar: 'toolCall.svg',
  name: t('template.tool_call'),
  intro: t('workflow.tool_call_desc'),
  showStatus: true,
  courseUrl: '/docs/workflow/modules/tool/',
  version: '481',
  isFolded: true,
  inputs: [
    {
      ...Input_Template_SettingAiModel,
      llmModelType: LLMModelTypeEnum.all,
    },
    {
      key: NodeInputKeyEnum.aiChatTemperature,
      renderTypeList: [FlowNodeInputTypeEnum.hidden], // Set in the pop-up window
      label: '',
      value: 0,
      valueType: WorkflowIOValueTypeEnum.number,
    },
    {
      key: NodeInputKeyEnum.aiChatMaxToken,
      renderTypeList: [FlowNodeInputTypeEnum.hidden], // Set in the pop-up window
      label: '',
      value: 2000,
      valueType: WorkflowIOValueTypeEnum.number,
    },
    {
      key: NodeInputKeyEnum.aiChatVision,
      renderTypeList: [FlowNodeInputTypeEnum.hidden],
      label: '',
      valueType: WorkflowIOValueTypeEnum.boolean,
      value: true,
    },

    {
      ...Input_Template_System_Prompt,
      label: t('core.ai.System Prompt'),
      description: systemPromptTip,
      placeholder: chatNodeSystemPromptTip,
    },
    Input_Template_History,
    {
      ...Input_Template_UserChatInput,
      label: t('tool_user_question'),
      toolDescription: t('tool_user_question_desc'),
    },
    Input_Template_UserChatInput2,
    {
      key: 'quoteQA',
      renderTypeList: [FlowNodeInputTypeEnum.settingDatasetQuotePrompt],
      label: '',
      debugLabel: '函数库',
      description: '',
      valueType: WorkflowIOValueTypeEnum.datasetQuote,
    },
  ],
  outputs: [
    {
      id: NodeOutputKeyEnum.answerText,
      key: NodeOutputKeyEnum.answerText,
      label: t('core.module.output.label.Ai response content'),
      description: t('core.module.output.description.Ai response content'),
      valueType: WorkflowIOValueTypeEnum.string,
      type: FlowNodeOutputTypeEnum.static,
    },
  ],
};
